package constant.milk.cashbook.select;

import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;

import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;
import constant.milk.cashbook.asset.MemoActivity;
import constant.milk.cashbook.asset.MoneyActivity;
import constant.milk.cashbook.asset.NameActivity;
import constant.milk.cashbook.bean.BankData;
import constant.milk.cashbook.bean.CategoryMainData;
import constant.milk.cashbook.bean.CategorySubData;
import constant.milk.cashbook.bean.CheckData;
import constant.milk.cashbook.bean.CreditData;
import constant.milk.cashbook.bean.GiftData;
import constant.milk.cashbook.bean.InOutData;
import constant.milk.cashbook.bean.PhoneData;
import constant.milk.cashbook.bean.RealData;
import constant.milk.cashbook.category.CategoryMainListActivity;
import constant.milk.cashbook.category.CategorySubListActivity;
import constant.milk.cashbook.database.DBSelectQuery;
import constant.milk.cashbook.database.DbDeleteQuery;
import constant.milk.cashbook.database.DbUpdateQuery;
import constant.milk.cashbook.insert.AssetListActivity;
import constant.milk.cashbook.insert.FanTypeActivity;
import constant.milk.cashbook.insert.InsertFanActivity;
import constant.milk.cashbook.insert.MoveAssetChoiceActivity;
import constant.milk.cashbook.photo.PhotoActivity;
import constant.milk.cashbook.tip.TipMap;
import constant.milk.cashbook.tip.TipInfoActivity;
import constant.milk.cashbook.util.MilkManager;
import constant.milk.cashbook.util.CalendarActivity;
import constant.milk.cashbook.util.MilkUtil;
import constant.milk.cashbook.util.TimeActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class SelectInfoFanActivity extends SuperActivity
{
	public static final int TYPE_REQUEST_CODE = 0;
	public static final int PERSON_REQUEST_CODE = 1;
	public static final int ASSET_REQUEST_CODE = 2;
	public static final int ASSET_LIST_REQUEST_CODE = 3;
	public static final int CATEGORY_MAIN_REQUEST_CODE = 4;
	public static final int CATEGORY_SUB_REQUEST_CODE = 5;
	public static final int CALENDER_REQUEST_CODE = 6;
	public static final int TIME_REQUEST_CODE = 7;
	public static final int MONEY_REQUEST_CODE = 8;
	public static final int MEMO_REQUEST_CODE = 9;
	public static final int FAN_BUTTON_REQUEST_CODE = 10;
	public static final int FAN_LIST_REQUEST_CODE = 11;
	public static final int PHOTO_REQUEST_CODE = 12;
	
	public static final String INOUT_INFO_FAN_ID = "INOUT_INFO_FAN_ID";
	
	private View typeView;
	private TextView typeTextView;
	
	private View personView;
	private TextView personTextView;
	
	private View assetView;
	private TextView assetTextView;
	
	private View assetNameView;
	private TextView assetNameTextView;
	
	private View mainCategoryView;
	private TextView mainCategoryTextView;
	
	private View subCategoryView;
	private TextView subCategoryTextView;
	
	private View dateView;
	private TextView dateTextView;
	
	private View timeView;
	private TextView timeTextView;
	
	private View money1View;
	private TextView money1TitleTextView;
	private TextView money1TextView;
	
	private TextView money2TitleTextView;
	private TextView money2TextView;
	
	private View memoView;
	private TextView memoTextView;
	
	private View photoView;
	private TextView photoTextView;
	
	private View moneyReView;
	private View fanButtonView;
	
	private ImageView typeArrow;
	private ImageView personArrow;
	
	private Button fanButton;
	private Button listButton;
	
	private Button deleteButton;
	private Button updateButton;
	
	private ArrayList<String> assetNameList;
	private ArrayList<String> categoryMainList;
	private ArrayList<String> categorySubList;
	
	private DBSelectQuery select;
	
	private int year;
	private int month;
	private int day;
	
	private String am_pm;
	private String hour;
	private String minute;
	
	private InOutData data;
	
	private MilkManager assetManager;
	
	private String photoPath;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.info_fan_activity);
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		typeView = findViewById(R.id.infoFanTypeView);
		typeTextView = (TextView) findViewById(R.id.infoFanTypeTextView);
		
		personView = findViewById(R.id.infoFanPersonView);
		personTextView = (TextView) findViewById(R.id.infoFanPersonTextView);
		
		assetView = findViewById(R.id.infoFanAssetView);
		assetTextView = (TextView) findViewById(R.id.infoFanAssetTextView);
		
		assetNameView = findViewById(R.id.infoFanAssetNameView);
		assetNameTextView = (TextView) findViewById(R.id.infoFanAssetNameTextView);
		
		mainCategoryView = findViewById(R.id.infoFanMainCategoryView);
		mainCategoryTextView = (TextView) findViewById(R.id.infoFanMainCategoryTextView);
		
		subCategoryView = findViewById(R.id.infoFanSubCategoryView);
		subCategoryTextView = (TextView) findViewById(R.id.infoFanSubCategoryTextView);
		
		dateView = findViewById(R.id.infoFanDateView);
		dateTextView = (TextView) findViewById(R.id.infoFanDateTextView);
		
		timeView = findViewById(R.id.infoFanTimeView);
		timeTextView = (TextView) findViewById(R.id.infoFanTimeTextView);
		
		money1View = findViewById(R.id.infoFanMoneyView);
		money1TitleTextView = (TextView) findViewById(R.id.infoFanMoneyTitleTextView);
		money1TextView = (TextView) findViewById(R.id.infoFanMoneyTextView);
		
		money2TitleTextView = (TextView) findViewById(R.id.infoFanMoney2TitleTextView);
		money2TextView = (TextView) findViewById(R.id.infoFanMoney2TextView);
		
		memoView = findViewById(R.id.infoFanMemoView);
		memoTextView = (TextView) findViewById(R.id.infoFanMemoTextView);
		
		photoView = findViewById(R.id.infoFanPhotoView);
		photoTextView = (TextView) findViewById(R.id.infoFanPhotoTextView);
		
		moneyReView = findViewById(R.id.infoFanReMoneyView);
		fanButtonView = findViewById(R.id.infoFanButtonView);
		
		typeArrow = (ImageView) findViewById(R.id.infoFanTypeArrow);
		personArrow = (ImageView) findViewById(R.id.infoFanPersonArrow);
		
		fanButton = (Button) findViewById(R.id.infoFanButton);
		listButton = (Button) findViewById(R.id.infoListButton);
		
		deleteButton = (Button) findViewById(R.id.deleteButton);
		updateButton = (Button) findViewById(R.id.updateButton);
	}

	@Override
	protected void setOnClick()
	{
		typeView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, FanTypeActivity.class);
				intent.putExtra(FanTypeActivity.FAN_TYPE_DATA, typeTextView.getText().toString());
				startActivityForResult(intent, TYPE_REQUEST_CODE);
			}
		});
		
		personView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, NameActivity.class);
				intent.putExtra(NameActivity.NAME_DATA, personTextView.getText().toString());
				startActivityForResult(intent, PERSON_REQUEST_CODE);
			}
		});
		
		assetView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, MoveAssetChoiceActivity.class);
				intent.putExtra(MoveAssetChoiceActivity.TYPE_DATA, assetTextView.getText().toString());
				intent.putExtra(MoveAssetChoiceActivity.MOVE_TYPE, 1);
				startActivityForResult(intent, ASSET_REQUEST_CODE);
			}
		});
		
		assetNameView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startAssetNameList();
			}
		});
		
		mainCategoryView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startCategoryMainList();
			}
		});
		
		subCategoryView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startCategorySubList();
			}
		});
		
		dateView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startCalendar();
			}
		});
		
		timeView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startTime();
			}
		});
		
		money1View.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startMoney();
			}
		});
		
		memoView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				startMemo();
			}
		});
		
		photoView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, PhotoActivity.class);
				intent.putExtra(PhotoActivity.PHOTH_PASH, photoPath);
				startActivityForResult(intent, PHOTO_REQUEST_CODE);
			}
		});
		
		fanButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, InsertFanActivity.class);
				intent.putExtra(InsertFanActivity.FAN_INSERT_ID, data.getId());
				
				if (data.getKind().equals("1"))
				{
					intent.putExtra(InsertFanActivity.INSERT_TYPE, InsertFanActivity.FAN_RETURN);
				}
				else if (data.getKind().equals("2"))
				{
					intent.putExtra(InsertFanActivity.INSERT_TYPE, InsertFanActivity.FAN_RECEIVE);
				}
				
				startActivityForResult(intent, FAN_BUTTON_REQUEST_CODE);
			}
		});
		
		listButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(superContext, SelectListActivity.class);
				intent.putExtra(INOUT_INFO_FAN_ID, data.getId());
				
				if (data.getKind().equals("1"))
				{
					intent.putExtra(SelectMainActivity.TYPE_FLAG, 3);
					intent.putExtra(SelectMainActivity.KIND_FLAG, 3);
				}
				else if (data.getKind().equals("2"))
				{
					intent.putExtra(SelectMainActivity.TYPE_FLAG, 3);
					intent.putExtra(SelectMainActivity.KIND_FLAG, 4);
				}
				
				startActivityForResult(intent, FAN_LIST_REQUEST_CODE);
			}
		});
		
		deleteButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				if (!assetManager.checkAsset(data))
				{
					return;
				}
				
				if (setDeleteData())
				{
					MilkUtil.showDialogFinish(superContext, "확인", "데이터 삭제에 성공하였습니다.");
				}
				else
				{
					MilkUtil.showDialog(superContext, "실패", "잠시후 다시해 주세요.");
				}
			}
		});
		
		updateButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				if (!assetManager.checkAsset(data))
				{
					return;
				}
				
				if (!checkUpdate())
				{
					return;
				}
				
				if (setUpdateData())
				{
					MilkUtil.showDialogFinish(superContext, "확인", "데이터 수정에 성공하였습니다.");
				}
				else
				{
					MilkUtil.showDialog(superContext, "실패", "잠시후 다시해 주세요.");
				}
			}
		});
	}
	
	@Override
	protected void setData()
	{
		assetManager = new MilkManager(superContext, superDb);
		select = new DBSelectQuery(superContext, superDb);
		
		Intent intent = getIntent();
		
		String id = intent.getStringExtra(INOUT_INFO_FAN_ID);
		
		DBSelectQuery query = new DBSelectQuery(superContext, superDb);
		data = query.getInOutId(id);
		
		typeTextView.setText(assetManager.getFanTypeId(data.getKind()));
		
		personTextView.setText(data.getPerson());
		
		assetTextView.setText(assetManager.getAssetId(data.getAsset()));
		
		setAssetNameData(assetManager.getAssetId(data.getAsset()));
		
		assetNameTextView.setText(data.getName());
		
		setCategoryMain();
		
		setCategorySub();
		
		mainCategoryTextView.setText(data.getMaincategory());

		subCategoryTextView.setText(data.getSubcategory());
		
		int [] datas = MilkUtil.getDateSet(data.getDate());
		
		year = datas[0];
		month = datas[1]-1;
		day = datas[2];
		
		if (Integer.parseInt(data.getAmpm()) == Calendar.AM)
		{
			am_pm = "AM";
		}
		else
		{
			am_pm = "PM";
		}
		
		if (Integer.parseInt(data.getTimehour()) < 10)
		{
			hour = "0" + data.getTimehour();
		}
		else
		{
			hour = data.getTimehour() + "";
		}
		
		if (Integer.parseInt(data.getTimeminute()) < 10)
		{
			minute = "0" + data.getTimeminute();
		}
		else
		{
			minute = data.getTimeminute() + "";
		}
		
		setDateView();
		setTimeView();
		
		money1TextView.setText(MilkUtil.getWon(data.getMoney()));
		
		memoTextView.setText(data.getMemo());
		
		if (data.getKind().equals("1"))
		{
			setTitle(getString(R.string.fanInInfo));
			money1TitleTextView.setText(getString(R.string.fanInMoney));
			money2TitleTextView.setText(getString(R.string.fanReturnMoney));
			fanButton.setText(getString(R.string.fanReturnInsert));
			listButton.setText(getString(R.string.fanReturnlist));
		}
		else if (data.getKind().equals("2"))
		{
			setTitle(getString(R.string.fanOutInfo));
			money1TitleTextView.setText(getString(R.string.fanOutMoney));
			money2TitleTextView.setText(getString(R.string.fanReceiveMoney));
			fanButton.setText(getString(R.string.fanReceiveInsert));
			listButton.setText(getString(R.string.fanReceivelist));
		}
		else if (data.getKind().equals("3"))
		{
			setTitle(getString(R.string.fanReturnInfo));
			money1TitleTextView.setText(getString(R.string.fanReturnMoney));
			moneyReView.setVisibility(View.GONE);
			fanButtonView.setVisibility(View.GONE);
			typeView.setClickable(false);
			personView.setClickable(false);
			typeArrow.setVisibility(View.GONE);
			personArrow.setVisibility(View.GONE);
		}
		else if (data.getKind().equals("4"))
		{
			setTitle(getString(R.string.fanReceiveInfo));
			money1TitleTextView.setText(getString(R.string.fanReceiveMoney));
			moneyReView.setVisibility(View.GONE);
			fanButtonView.setVisibility(View.GONE);
			typeView.setClickable(false);
			personView.setClickable(false);
			typeArrow.setVisibility(View.GONE);
			personArrow.setVisibility(View.GONE);
		}
		
		setLinkIdMoney();
		
		if (data.getPhotopath().equals(""))
		{
			photoTextView.setText("없음");
		}
		else
		{
			photoTextView.setText("있음");
		}
		
		photoPath = data.getPhotopath();
	}

	private void setLinkIdMoney()
	{
		ArrayList<InOutData> linkList = select.getInOutLinkId(data.getId());
		
		BigDecimal linkMoney = BigDecimal.ZERO;
		
		for (int i = 0; i < linkList.size(); i++)
		{
			BigDecimal money = new BigDecimal(linkList.get(i).getMoney());
			
			linkMoney = linkMoney.add(money);
		}
		
		money2TextView.setText(MilkUtil.getWon(linkMoney.toString()));
	}
	
	private boolean checkUpdate()
	{
		if (personTextView.getText().toString().equals(""))
		{
			MilkUtil.showToast(superContext, "사람을 입력해 주세요.");
			return false;
		}
		
		if (assetNameTextView.getText().toString().equals(""))
		{
			MilkUtil.showToast(superContext, "자산을 추가해 주세요.");
			return false;
		}
		
		if (mainCategoryTextView.getText().toString().equals(""))
		{
			MilkUtil.showToast(superContext, "메인 카테고리를 추가해 주세요.");
			return false;
		}
		
		if (subCategoryTextView.getText().toString().equals(""))
		{
			MilkUtil.showToast(superContext, "서브 카테고리를 추가해 주세요.");
			return false;
		}
		
		if (money1TextView.getText().toString().equals(""))
		{
			MilkUtil.showToast(superContext, "금액을 정확히 입력해 주세요.");
			return false;
		}
		
		return true;
	}
	
	private boolean setDeleteData()
	{
		DbDeleteQuery query = null;
		try
		{
			query = new DbDeleteQuery(superContext, superDb);
			
			query.setBeginTansaction();
			
			query.setInOutDelete(data.getId());
			
			if (data.getKind().equals("1") || data.getKind().equals("2"))
			{
				query.setInOutDeleteLinkId(data.getId());
			}
			
			if (data.getPhotopath() != null || !data.getPhotopath().equals(""))
			{
				try
				{
					File file = new File(data.getPhotopath());

					file.delete();

				} catch (Exception e)
				{
					e.printStackTrace();
				}
			}
			
			if (typeTextView.getText().toString().equals(getString(R.string.fanIn))) // 빌림
			{
				assetManager.setAssetMoney(assetManager.getAssetId(data.getAsset()), 
						data.getName(), data.getMoney(), 0);
				
				ArrayList<InOutData> list = select.getInOutLinkId(data.getId());
				
				for (int i = 0; i < list.size(); i++)
				{
					InOutData linkData = list.get(i);
					
					assetManager.setAssetMoney(assetManager.getAssetId(linkData.getAsset()), 
							linkData.getName(), linkData.getMoney(), 1);
				}
			}
			else if (typeTextView.getText().toString().equals(getString(R.string.fanOut))) // 빌려줌
			{
				assetManager.setAssetMoney(assetManager.getAssetId(data.getAsset()), 
						data.getName(), data.getMoney(), 1);
				
				ArrayList<InOutData> list = select.getInOutLinkId(data.getId());
				
				for (int i = 0; i < list.size(); i++)
				{
					InOutData linkData = list.get(i);
					
					assetManager.setAssetMoney(assetManager.getAssetId(linkData.getAsset()), 
							linkData.getName(), linkData.getMoney(), 0);
				}
			}
			else if (typeTextView.getText().toString().equals(getString(R.string.fanReturn))) // 갚음
			{
				assetManager.setAssetMoney(assetManager.getAssetId(data.getAsset()), 
						data.getName(), data.getMoney(), 1);
			}
			else if (typeTextView.getText().toString().equals(getString(R.string.fanReceive))) // 받음
			{
				assetManager.setAssetMoney(assetManager.getAssetId(data.getAsset()), 
						data.getName(), data.getMoney(), 0);
			}
			
			query.setSuccessful();
		} catch (Exception e)
		{
			e.printStackTrace();
			return false;
		} finally {
			try
			{
				query.setEndTansaction();
			} catch (Exception e)
			{
				e.printStackTrace();
				return false;
			}
		}
		
		return true;
	}
	
	private boolean setUpdateData()
	{
		DbUpdateQuery query = null;
		
		try
		{
			query = new DbUpdateQuery(superContext, superDb);
			
			query.setBeginTansaction();
			
			HashMap<String, String> map = new HashMap<String, String>();
			
			map.put("type", "3");
			
			if (typeTextView.getText().toString().equals(getString(R.string.fanIn)))
			{
				map.put("kind", "1");
			}
			else if (typeTextView.getText().toString().equals(getString(R.string.fanOut)))
			{
				map.put("kind", "2");
			}
			else if (typeTextView.getText().toString().equals(getString(R.string.fanReturn)))
			{
				map.put("kind", "3");
			}
			else if (typeTextView.getText().toString().equals(getString(R.string.fanReceive)))
			{
				map.put("kind", "4");
			}
			
			map.put("person", personTextView.getText().toString());
			map.put("asset", assetManager.getAssetStr(assetTextView.getText().toString()));
			map.put("name", assetNameTextView.getText().toString());
			map.put("maincategory", mainCategoryTextView.getText().toString());
			map.put("subcategory", subCategoryTextView.getText().toString());
			map.put("date", MilkUtil.getDateDB(year, month+1, day));
			map.put("ampm", MilkUtil.getAmPm(am_pm));
			map.put("timehour", hour);
			map.put("timeminute", minute);
			map.put("money", MilkUtil.getCommaDel(money1TextView.getText().toString()));
			map.put("memo", memoTextView.getText().toString());
			map.put("photopath", photoPath);
			
			query.setInOutUpdate(map, data.getId());
			
			if (data.getKind().equals("1") || data.getKind().equals("2"))
			{
				// 빌려준에서 빌림으로 변경되면 연결된 해결 데이터도 변경한다. 
				map.clear();
				
				if (typeTextView.getText().toString().equals(getString(R.string.fanIn)))
				{
					map.put("kind", "3");
				}
				else
				{
					map.put("kind", "4");
				}
				
				query.setInOutUpdateLinkId(map, data.getId());
			}
			
			if (typeTextView.getText().toString().equals(getString(R.string.fanIn))) // 빌림
			{
				assetManager.setAssetMoney(assetManager.getAssetId(data.getAsset()), 
						data.getName(), data.getMoney(), 0);
				
				ArrayList<InOutData> list = select.getInOutLinkId(data.getId());
				
				for (int i = 0; i < list.size(); i++)
				{
					InOutData linkData = list.get(i);
					
					assetManager.setAssetMoney(assetManager.getAssetId(linkData.getAsset()), 
							linkData.getName(), linkData.getMoney(), 1);
				}
				
				assetManager.setAssetMoney(assetTextView.getText().toString(), 
						assetNameTextView.getText().toString(), 
						money1TextView.getText().toString(), 1);
				
				for (int i = 0; i < list.size(); i++)
				{
					InOutData linkData = list.get(i);
					
					assetManager.setAssetMoney(assetManager.getAssetId(linkData.getAsset()), 
							linkData.getName(), linkData.getMoney(), 0);
				}
			}
			else if (typeTextView.getText().toString().equals(getString(R.string.fanOut))) // 빌려줌
			{
				assetManager.setAssetMoney(assetManager.getAssetId(data.getAsset()), 
						data.getName(), data.getMoney(), 1);
				
				ArrayList<InOutData> list = select.getInOutLinkId(data.getId());
				
				for (int i = 0; i < list.size(); i++)
				{
					InOutData linkData = list.get(i);
					
					assetManager.setAssetMoney(assetManager.getAssetId(linkData.getAsset()), 
							linkData.getName(), linkData.getMoney(), 0);
				}
				
				assetManager.setAssetMoney(assetTextView.getText().toString(), 
						assetNameTextView.getText().toString(), 
						money1TextView.getText().toString(), 0);
				
				for (int i = 0; i < list.size(); i++)
				{
					InOutData linkData = list.get(i);
					
					assetManager.setAssetMoney(assetManager.getAssetId(linkData.getAsset()), 
							linkData.getName(), linkData.getMoney(), 1);
				}
			}
			else if (typeTextView.getText().toString().equals(getString(R.string.fanReturn))) // 갚음
			{
				assetManager.setAssetMoney(assetManager.getAssetId(data.getAsset()), 
						data.getName(), data.getMoney(), 1);
				
				assetManager.setAssetMoney(assetTextView.getText().toString(), 
						assetNameTextView.getText().toString(), 
						money1TextView.getText().toString(), 0);
			}
			else if (typeTextView.getText().toString().equals(getString(R.string.fanReceive))) // 받음
			{
				assetManager.setAssetMoney(assetManager.getAssetId(data.getAsset()), 
						data.getName(), data.getMoney(), 0);
				
				assetManager.setAssetMoney(assetTextView.getText().toString(), 
						assetNameTextView.getText().toString(), 
						money1TextView.getText().toString(), 1);
			}
			
			query.setSuccessful();
		} catch (Exception e)
		{
			e.printStackTrace();
			return false;
		} finally {
			try
			{
				query.setEndTansaction();
			} catch (Exception e)
			{
				e.printStackTrace();
				return false;
			}
		}
		
		return true;
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		super.onActivityResult(requestCode, resultCode, data);
		
		if (resultCode != Activity.RESULT_OK)
		{
			return;
		}
		
		if (requestCode == TYPE_REQUEST_CODE)
		{
			String str = data.getStringExtra(FanTypeActivity.FAN_TYPE_DATA);
			typeTextView.setText(str);
		}
		else if (requestCode == PERSON_REQUEST_CODE)
		{
			String str = data.getStringExtra(NameActivity.NAME_DATA);
			personTextView.setText(str);
		}
		else if (requestCode == ASSET_REQUEST_CODE)
		{
			String str = data.getStringExtra(MoveAssetChoiceActivity.TYPE_DATA);
			assetTextView.setText(str);
			
			setAssetNameData(str);
		}
		else if (requestCode == ASSET_LIST_REQUEST_CODE)
		{
			String str = data.getStringExtra(AssetListActivity.ASSET_NAME_DATA);
			assetNameTextView.setText(str);
		}
		else if (requestCode == CATEGORY_MAIN_REQUEST_CODE)
		{
			String str = data.getStringExtra(CategoryMainListActivity.CATEGORY_MAIN_NAME_DATA);
			mainCategoryTextView.setText(str);
			
			setCategorySub();
			
		}
		else if (requestCode == CATEGORY_SUB_REQUEST_CODE)
		{
			String str = data.getStringExtra(CategorySubListActivity.CATEGORY_SUB_NAME_DATA);
			subCategoryTextView.setText(str);
			
		}
		else if (requestCode == CALENDER_REQUEST_CODE)
		{
			Calendar cal = Calendar.getInstance();
			year = data.getIntExtra(CalendarActivity.YEAR, cal.get(Calendar.YEAR));
			month = data.getIntExtra(CalendarActivity.MONTN, cal.get(Calendar.MONTH));
			day = data.getIntExtra(CalendarActivity.DAY, cal.get(Calendar.DAY_OF_MONTH));
			setDateView();
			
		}
		else if (requestCode == TIME_REQUEST_CODE)
		{
			am_pm = data.getStringExtra(TimeActivity.TIME_AM_PM_DATA);
			hour = data.getStringExtra(TimeActivity.TIME_HOUR_DATA);
			minute = data.getStringExtra(TimeActivity.TIME_MINUTE_DATA);
			setTimeView();
			
		}
		else if (requestCode == MONEY_REQUEST_CODE)
		{
			String money = data.getStringExtra(MoneyActivity.MONEY_DATA);
			
			money1TextView.setText(money);
		}
		else if (requestCode == MEMO_REQUEST_CODE)
		{
			String memo = data.getStringExtra(MemoActivity.MEMO_DATA);
			
			memoTextView.setText(memo);
		}
		else if (requestCode == FAN_BUTTON_REQUEST_CODE)
		{
			setLinkIdMoney();
		}
		else if (requestCode == FAN_LIST_REQUEST_CODE)
		{
			setLinkIdMoney();
		}
		else if (requestCode == PHOTO_REQUEST_CODE)
		{
			String path = data.getStringExtra(PhotoActivity.PHOTH_PASH);
			
			photoPath = path;
			
			if (photoPath.equals(""))
			{
				photoTextView.setText("없음");
			}
			else
			{
				photoTextView.setText("있음");
			}
		}
	}
	
	private void startAssetNameList()
	{
		Intent intent = new Intent(superContext, AssetListActivity.class);
		intent.putExtra(AssetListActivity.ASSET_NAME_DATA, assetNameTextView.getText().toString());
		intent.putExtra(AssetListActivity.ASSET_TYPE_DATA, assetTextView.getText().toString());
		startActivityForResult(intent, ASSET_LIST_REQUEST_CODE);
	}
	
	private void startCategoryMainList()
	{
		Intent intent = new Intent(superContext, CategoryMainListActivity.class);
		intent.putExtra(CategoryMainListActivity.CATEGORY_MAIN_NAME_DATA, mainCategoryTextView.getText().toString());
		intent.putExtra(CategoryMainListActivity.CATEGORY_MAIN_LIST_DATA, categoryMainList);
		startActivityForResult(intent, CATEGORY_MAIN_REQUEST_CODE);
	}
	
	private void startCategorySubList()
	{
		Intent intent = new Intent(superContext, CategorySubListActivity.class);
		intent.putExtra(CategorySubListActivity.CATEGORY_MAIN_NAME_DATA, mainCategoryTextView.getText().toString());
		intent.putExtra(CategorySubListActivity.CATEGORY_SUB_NAME_DATA, subCategoryTextView.getText().toString());
		intent.putExtra(CategorySubListActivity.CATEGORY_SUB_LIST_DATA, categorySubList);
		startActivityForResult(intent, CATEGORY_SUB_REQUEST_CODE);
	}
	
	private void startCalendar()
	{
		Intent intent = new Intent(superContext, CalendarActivity.class);
		intent.putExtra(CalendarActivity.YEAR, year);
		intent.putExtra(CalendarActivity.MONTN, month);
		intent.putExtra(CalendarActivity.DAY, day);
		startActivityForResult(intent, CALENDER_REQUEST_CODE);
	}
	
	private void startTime()
	{
		Intent intent = new Intent(superContext, TimeActivity.class);
		intent.putExtra(TimeActivity.TIME_AM_PM_DATA, am_pm);
		intent.putExtra(TimeActivity.TIME_HOUR_DATA, hour);
		intent.putExtra(TimeActivity.TIME_MINUTE_DATA, minute);
		startActivityForResult(intent, TIME_REQUEST_CODE);
	}
	
	private void startMoney()
	{
		Intent intent = new Intent(superContext, MoneyActivity.class);
		intent.putExtra(MoneyActivity.MONEY_DATA, money1TextView.getText().toString());
		startActivityForResult(intent, MONEY_REQUEST_CODE);
	}
	
	private void startMemo()
	{
		Intent intent = new Intent(superContext, MemoActivity.class);
		intent.putExtra(MemoActivity.MEMO_DATA, memoTextView.getText().toString());
		startActivityForResult(intent, MEMO_REQUEST_CODE);
	}

	private void setAssetNameData(String str)
	{
		DBSelectQuery query = new DBSelectQuery(superContext, superDb);
		
		assetNameList = new ArrayList<String>();
		
		if (str.equals(getString(R.string.realAsset)))
		{
			ArrayList<RealData> list = query.getRealList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("현금을 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.bankAsset)))
		{
			ArrayList<BankData> list = query.getBankList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("통장을 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.checkCardAsset)))
		{
			ArrayList<CheckData> list = query.getCheckList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("체크카드를 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.creditCardAsset)))
		{
			ArrayList<CreditData> list = query.getCreditList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("신용카드를 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.phoneAsset)))
		{
			ArrayList<PhoneData> list = query.getPhoneList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("핸드폰을 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
		}
		else if (str.equals(getString(R.string.giftCardAsset)))
		{
			ArrayList<GiftData> list = query.getGiftList();
			
			if (list == null || list.size() < 1)
			{
				assetNameTextView.setText("");
				assetNameTextView.setHint("상품권을 추가해주세요.");
				return;
			}
			
			assetNameTextView.setText(list.get(0).getName());
			
			for (int i = 0; i < list.size(); i++)
			{
				assetNameList.add(list.get(i).getName());
			}
		}
	}
	
	private void setCategoryMain()
	{
		ArrayList<CategoryMainData> list = select.getCategoryMainList();
		
		if (list == null || list.size() < 1)
		{
			mainCategoryTextView.setText("");
			mainCategoryTextView.setHint("카테고리를 추가해주세요.");
			return;
		}
		
		mainCategoryTextView.setText(list.get(0).getName());
		
		categoryMainList = new ArrayList<String>();
		
		for (int i = 0; i < list.size(); i++)
		{
			categoryMainList.add(list.get(i).getName());
		}
	}
	
	private void setCategorySub()
	{
		if (mainCategoryTextView.getText().toString().equals(""))
		{
			subCategoryTextView.setText("");
			subCategoryTextView.setHint("카테고리를 추가해주세요.");
			return;
		}
		
		CategoryMainData data = select.getCategoryMainName(mainCategoryTextView.getText().toString());
		
		ArrayList<CategorySubData> list = select.getCategorySubList(data.getId());
		
		if (list == null || list.size() < 1)
		{
			subCategoryTextView.setText("");
			subCategoryTextView.setHint("카테고리를 추가해주세요.");
			return;
		}
		
		subCategoryTextView.setText(list.get(0).getName());
		
		categorySubList = new ArrayList<String>();
		
		for (int i = 0; i < list.size(); i++)
		{
			categorySubList.add(list.get(i).getName());
		}
	}
	
	private void setDateView()
	{
		dateTextView.setText(MilkUtil.getDate(year, month+1, day));
	}
	
	private void setTimeView()
	{
		timeTextView.setText(MilkUtil.getTime(am_pm, hour, minute));
	}

	@Override
	protected void tipButton()
	{
		Intent intent = new Intent(superContext, TipInfoActivity.class);
		intent.putExtra(TipInfoActivity.TIP_ID, TipMap.TIP_SELECT_INFO_FAN);
		startActivity(intent);
	}
}
